﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using UWP.Douban.Api;
using UWP.Douban.Models;
using UWP.Douban.Views;
using Windows.UI.Xaml.Navigation;

namespace UWP.Douban.Mvvm
{
    public class ReplyCommentVm: BaseVm
    {
        private Topic _currentTopic;
        private string _content;
        public ReplyCommentVm()
        {
            SendCommand = new RelayCommand(Send);
        }

        

        public string Content
        {
            get
            {
                return _content;
            }
            set
            {
                if (value == _content) return;
                _content = value;
                OnPropertyChanged();
            }
        }

        public ICommand SendCommand { get; set; }

        public override void OnNavigatedTo(NavigationEventArgs e)
        {
            _currentTopic = e.Parameter as Topic;

            Content = string.Empty;
            base.OnNavigatedTo(e);
        }

        private async void Send()
        {
            var comment = await GroupApi.GPAddComment(_currentTopic.Id, Content);
            if (comment != null)
            {
                GoBack();
            }
        }
    }
}
